﻿<dialogs:DialogWindow x:Class="Modules.Artists.Views.ArtistEditDialog"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:converters="clr-namespace:Common.Dialogs.Converters;assembly=Common.Dialogs"
             xmlns:controls="clr-namespace:Common.Controls.Controls;assembly=Common.Controls"
             xmlns:commands="clr-namespace:Common.Commands;assembly=Common.Commands"
             xmlns:dialogs="clr-namespace:Common.Dialogs;assembly=Common.Dialogs"
             xmlns:prismCommand="clr-namespace:Microsoft.Practices.Composite.Presentation.Commands;assembly=Microsoft.Practices.Composite.Presentation"
             xmlns:toolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"
             xmlns:enums="clr-namespace:Modules.Artists.Enums"
             mc:Ignorable="d" 
             x:Name="dialogWindow"
             WindowStyle="None" AllowsTransparency="True" ResizeMode="NoResize"
             Background="Transparent" WindowStartupLocation="CenterScreen"
             WindowResult="{Binding DialogResult}"
             Height="446" Width="634">
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Common.Dialogs;component/Styles/CommonStyles.xaml"/>
            </ResourceDictionary.MergedDictionaries>

            <converters:HeaderTextConverter x:Key="HeaderTextConverter" EntityName="artist"/>
        </ResourceDictionary>
    </Window.Resources>
    <Grid x:Name="LayoutRoot"
          controls:BusyIndicatorBehavior.AddMargins="True" 
          controls:BusyIndicatorBehavior.BusyState="{Binding IsBusy}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Border x:Name="HeaderBorder" Grid.Row="0" BorderThickness="2,2,2,0" CornerRadius="10,10,0,0" BorderBrush="Black" Background="SteelBlue"
                MouseDown="HeaderBorder_MouseDown"
                >
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <StackPanel HorizontalAlignment="Left" Grid.Column="0">
                    <TextBlock Text="{Binding IsEditMode,Converter={StaticResource HeaderTextConverter}}" Style="{StaticResource DialogHeaderTextStyle}"/>
                </StackPanel>
                <StackPanel HorizontalAlignment="Right" Grid.Column="1">
                    <Button VerticalAlignment="Center" Margin="8" Style="{StaticResource CloseButtonStyle}"
                            prismCommand:Click.Command="{Binding CancelCommand}"
                            >
                        <Button.Content>
                            <Image Source="/Common.Dialogs;component/Images/305_Close_16x16_72.png" Width="12" Height="12"/>
                        </Button.Content>
                    </Button>
                </StackPanel>
            </Grid>
        </Border>
        <Border Grid.Row="1" BorderThickness="2,0,2,2" CornerRadius="0,0,4,4" BorderBrush="Black" Background="LightGray">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="*"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <TabControl Grid.Column="0" Margin="4" 
                            >
                    <TabItem Header="General" DataContext="{Binding Artist}">
                        <TabItem.Tag>
                            <enums:ArtistTabsEnum>General</enums:ArtistTabsEnum>
                        </TabItem.Tag>
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*"/>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>
                            <Grid Grid.Row="0">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition/>
                                </Grid.RowDefinitions>

                                <TextBlock Text="Artist name:" FontWeight="Bold" Grid.Row="0" Grid.Column="0" Margin="16,8,8,8"
                                VerticalAlignment="Center" HorizontalAlignment="Right"/>
                                <TextBox Text="{Binding Name,ValidatesOnExceptions=True}" Grid.Row="0" Grid.Column="1" Margin="8" Height="24"/>

                                <TextBlock Text="Private marks:" FontWeight="Bold" Grid.Row="1" Grid.Column="0" Margin="16,8,8,8"
                                VerticalAlignment="Top" HorizontalAlignment="Right"/>
                                <TextBox Text="{Binding PrivateMarks}" Grid.Row="1" Grid.Column="1" Grid.RowSpan="2" Margin="8"
                                         AcceptsReturn="True" AcceptsTab="True" TextWrapping="Wrap"
                                         />
                            </Grid>
                        </Grid>
                    </TabItem>
                    <TabItem Header="Biography" DataContext="{Binding Artist}">
                        <TabItem.Tag>
                            <enums:ArtistTabsEnum>Biography</enums:ArtistTabsEnum>
                        </TabItem.Tag>
                        <Grid Grid.Row="0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <TextBlock Text="Biography:" FontWeight="Bold" Grid.Column="0" Margin="16,8,8,8"
                               VerticalAlignment="Top" HorizontalAlignment="Right"/>
                            <TextBox Text="{Binding Biography}" Grid.Column="1" Margin="8"
                                     AcceptsReturn="True" AcceptsTab="True" TextWrapping="Wrap"
                                     />
                        </Grid>
                    </TabItem>
                </TabControl>
                <Grid Grid.Column="1" Grid.RowSpan="2">
                    <GroupBox Header="Tags" Width="200" Grid.Row="0" Margin="4">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*"/>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>
                            <ListView x:Name="TagsListView" Margin="8"
                                      ItemsSource="{Binding Artist.Tags}"
                                      IsSynchronizedWithCurrentItem="True"
                                      commands:MouseDoubleClick.Command="{Binding EditTagCommand}"
                                      ItemContainerStyle="{StaticResource ListViewItemCommonStyle}"
                                      >
                                <ListView.ItemTemplate>
                                    <DataTemplate>
                                        <Border BorderBrush="LightSteelBlue" Background="LightSteelBlue" BorderThickness="1" CornerRadius="8" Margin="2,1,2,1">
                                            <Grid Margin="4,2,4,2" Height="24">
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="*"/>
                                                    <ColumnDefinition Width="Auto"/>
                                                </Grid.ColumnDefinitions>
                                                <TextBlock Text="{Binding Name}" FontWeight="Bold" Grid.Column="0" VerticalAlignment="Center"/>
                                                <Button Style="{StaticResource TransparentImageButtonStyle}" Grid.Column="1" Margin="6,0,0,0" VerticalAlignment="Center"
                                                        ToolTip="Detach this tag from artist" Cursor="Hand"
                                                        prismCommand:Click.Command="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type Window}}, Path=DataContext.DetachTagCommand}"
                                                        prismCommand:Click.CommandParameter="{Binding}"
                                                        >
                                                    <Button.Content>
                                                        <Image Source="/Common.Dialogs;component/Images/Remove_16x16.png" Height="16" Width="16"/>
                                                    </Button.Content>
                                                </Button>
                                            </Grid>
                                        </Border>
                                    </DataTemplate>
                                </ListView.ItemTemplate>
                            </ListView>
                            <Grid Grid.Row="1" Margin="8,0,8,8">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="Auto"/>
                                </Grid.ColumnDefinitions>
                                <toolkit:AutoCompleteBox x:Name="TagAutocompleteBox" Grid.Column="0"
                                                     ItemsSource="{Binding Tags}"
                                                     ItemFilter="{Binding FilterTagCommand}"
                                                     SelectedItem="{Binding SelectedTag,Mode=TwoWay}"
                                                     Text="{Binding NewTagName,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
                                                     IsTextCompletionEnabled="True"
                                                     commands:PreviewKeyDown.Command="{Binding AttachTagKeyboardCommand}"
                                                     ValueMemberPath="Name"
                                                     >
                                <toolkit:AutoCompleteBox.ItemTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding Name}"/>
                                    </DataTemplate>
                                </toolkit:AutoCompleteBox.ItemTemplate>
                            </toolkit:AutoCompleteBox>
                                <Button x:Name="AttachTagButton" Grid.Column="1"
                                        Style="{StaticResource ImageButtonStyle}"
                                        ToolTip="Assign tag to this artist"
                                        prismCommand:Click.Command="{Binding AttachTagCommand}"
                                        
                                        >
                                    <Button.Content>
                                        <Image Source="/Common.Dialogs;component/Images/command_link_16x16.png" Width="16" Height="16"/>
                                    </Button.Content>
                                </Button>
                                        
                            </Grid>
                        </Grid>
                    </GroupBox>
                </Grid>
                <StackPanel Grid.Row="1" HorizontalAlignment="Right" Orientation="Horizontal" Margin="12,0,0,12">
                    <Button x:Name="OkButton" Content="Ok" Width="75" IsDefault="True" Margin="6"
                            Style="{StaticResource DialogButtonStyle}"
                            prismCommand:Click.Command="{Binding SuccessCommand}"
                            prismCommand:Click.CommandParameter="{Binding ElementName=dialogWindow}"
                            />
                    <Button x:Name="CancelButton" Content="Cancel" Width="75" IsDefault="True" Margin="6"
                            Style="{StaticResource DialogButtonStyle}"
                            prismCommand:Click.Command="{Binding CancelCommand}"
                            />
                </StackPanel>
            </Grid>
        </Border>
    </Grid>
</dialogs:DialogWindow>
